package cn.edu.lcu.cs.javateaching.io;

import java.io.*;

/**
 * 变量名不规范，如26行变量car；缩进乱七八糟，大括号套错了代码块。
 * 
 * @author Ling
 *
 */
public class demo4 {
	public static void main(String[] args) {
		FileInputStream fis = null;
		try {
			fis = new FileInputStream("D://wbq.txt");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			System.out.println("要拷贝的文件找不到");
		}
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream("D://streamCopy.txt");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			System.out.println("目标路径不存在");
		}
		byte[] car = new byte[1024];
		int i;
		try {
			while ((i = fis.read(car)) != -1) {
				fos.write(car);
			}
			fos.close();
			fis.close();
			System.out.println("字节流拷贝文件成功！");
			FileReader fir = new FileReader("D://wbq.txt");
			FileWriter fwr = new FileWriter("D://zifuCopy.txt");
			BufferedReader bufferedReader = new BufferedReader(fir);
			BufferedWriter bufferedWriter = new BufferedWriter(fwr);
			// 字符流文件拷贝只能操作纯文本文件
			while ((i = bufferedReader.read()) != -1) {
				// System.out.print((char)i);
				bufferedWriter.write(i);
				bufferedWriter.flush();
			}

			bufferedReader.close();
			bufferedWriter.close();
			System.out.println("字符流文件拷贝成功！");
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
